home *** CD-ROM | disk | FTP | other *** search
/ Amiga Mag HDD Backup / Amiga Mag HDD Backup.zip / Amiga Mag HDD Backup / Alexander.img.bin / Alexander.img / ***9.11 All NEWer important / 10.2 / Finch⁄Front Ending C / Listing3.txt < prev   
Text File  |  1983-05-04  |  4KB  |  156 lines

  1. Listing 3. CanDoMJC.c C Program
  2.  
  3.  
  4.  
  5.  
  6. /*----------  INCLUDE HEADER FILE  ----------*/
  7.  
  8. #include "CanDoMJC.h"
  9.  
  10. /*----------  SUPPORT FUNCTIONS  ----------*/
  11.  
  12. void MJPlot(struct Window *w, WORD maxdwell, LONG scale,
  13.             struct ComplexRange *cr, struct complex *jc, UBYTE type)
  14. {
  15.    struct RastPort *rp;
  16.    struct complex c, z, zloop;
  17.    struct IntuiMessage *message;
  18.    WORD xstart=0, ystart=0, x, y, xend, yend;
  19.    WORD count;
  20.    DOUBLE rstep, istep, zrtemp;
  21.    ULONG oldIDCMPFlags;
  22.  
  23.    rp = w->RPort;
  24.    oldIDCMPFlags = w->IDCMPFlags;
  25.    ModifyIDCMP(w, MOUSEBUTTONS);
  26.  
  27.    xend = 8*(rp->BitMap->BytesPerRow)-1;
  28.    yend = (rp->BitMap->Rows)-1;
  29.    rstep = (cr->rmax - cr->rmin)*scale/xend;
  30.    istep = (cr->imax - cr->imin)*scale/yend;
  31.  
  32.    SetRast(rp,0);
  33.    if (type == MANDELBROT) {
  34.       for (c.i = cr->imax, y=ystart ; y<=yend ; c.i-=istep, y+=scale) {
  35.      if(message = (struct IntuiMessage *)GetMsg(w->UserPort)) {
  36.         ReplyMsg((struct Message *)message);
  37.         break;
  38.      } /* if */
  39.      for (c.r = cr->rmin, x=xstart ; x<=xend ; c.r+=rstep, x+=scale) {
  40.         zloop.r = zloop.i = 0.;
  41.         count = 0;
  42.  
  43.         do {
  44.            zrtemp = zloop.r*zloop.r - zloop.i*zloop.i + c.r;
  45.            zloop.i = 2.*zloop.r*zloop.i + c.i;
  46.            zloop.r = zrtemp;
  47.            if((zloop.r*zloop.r + zloop.i*zloop.i) > 4.) break;
  48.            ++count;
  49.         } while (count < maxdwell);
  50.  
  51.         SetAPen(rp, count);
  52.         if (scale == 1)
  53.            WritePixel(rp, x, y);
  54.         else
  55.            RectFill(rp, x, y, x+scale-1, y+scale-1);
  56.      } /* for */
  57.       } /* for */
  58.    } /* if */
  59.  
  60.    else if (type == JULIA) {
  61.       for (z.i = cr->imax, y=ystart ; y<=yend ; z.i-=istep, y+=scale) {
  62.          if(message = (struct IntuiMessage *)GetMsg(w->UserPort)) {
  63.             ReplyMsg((struct Message *)message);
  64.             break;
  65.          } /* if */
  66.          for (z.r = cr->rmin, x=xstart ; x<=xend ; z.r+=rstep, x+=scale) {
  67.             zloop.r = z.r;
  68.             zloop.i = z.i;
  69.             count = 0;
  70.  
  71.             do {
  72.                if((zloop.r*zloop.r + zloop.i*zloop.i) > 4.) break;
  73.                ++count;
  74.                zrtemp = zloop.r*zloop.r - zloop.i*zloop.i + jc->r;
  75.                zloop.i = 2.*zloop.r*zloop.i + jc->i;
  76.                zloop.r = zrtemp;
  77.             } while (count < maxdwell);
  78.  
  79.         SetAPen(rp, count);
  80.         if (scale == 1)
  81.            WritePixel(rp, x, y);
  82.         else
  83.            RectFill(rp, x, y, x+scale-1, y+scale-1);
  84.      } /* for */
  85.       } /* for */
  86.    } /* else if */
  87.  
  88.    ModifyIDCMP(w, oldIDCMPFlags);
  89.  
  90. } /* MJPlot */
  91.  
  92. void SetComplexRange(struct ComplexRange *r, DOUBLE rmin,
  93.                      DOUBLE rmax, DOUBLE imin, DOUBLE imax)
  94. {
  95.    r->rmin = rmin;
  96.    r->rmax = rmax;
  97.    r->imin = imin;
  98.    r->imax = imax;
  99. } /* SetComplexRange */
  100.  
  101.  
  102. /*---------------  MAIN PROGRAM  ---------------*/
  103.  
  104. LONG main (int argc, char *argv[])
  105. {
  106.    /* LOCAL VARIABLES */
  107.    
  108.    struct Window *CanDoWin;
  109.    struct ComplexRange mrange;
  110.    struct ComplexRange jrange; 
  111.    struct complex jc;
  112.  
  113.    char **dummy=NULL;
  114.    char MandOrJulia;
  115.  
  116.    WORD maxdwell;
  117.    WORD resolution;
  118.  
  119.    DOUBLE rmin, rmax, imin, imax;
  120.  
  121.    /* OPEN LIBRARIES */
  122.    
  123.    if (!OpenLibraries()) {
  124.       CloseLibraries();
  125.       return 1L;
  126.    } /* if */
  127.  
  128.    /* EXECUTE PROGRAM IF RIGHT NUMBER OF ARGUMENTS */
  129.    
  130.    if (argc >= 9) {
  131.       CanDoWin=(struct Window *)(strtoul(argv[1],dummy,10));
  132.       maxdwell=(WORD)(strtoul(argv[2],dummy,10));
  133.       resolution=(WORD)(strtoul(argv[3],dummy,10));
  134.       rmin=strtod(argv[4],dummy);
  135.       rmax=strtod(argv[5],dummy);
  136.       imin=strtod(argv[6],dummy);
  137.       imax=strtod(argv[7],dummy);
  138.       MandOrJulia=*(argv[8]);
  139.       
  140.       if (MandOrJulia == 'M') {
  141.         SetComplexRange(&mrange, rmin, rmax, imin, imax);
  142.         MJPlot(CanDoWin, maxdwell, resolution, &mrange, NULL, MANDELBROT);
  143.       } /* if */
  144.  
  145.       else if (MandOrJulia == 'J') {
  146.         jc.r=strtod(argv[9],dummy);
  147.         jc.i=strtod(argv[10],dummy);
  148.         SetComplexRange(&jrange, rmin, rmax, imin, imax);
  149.         MJPlot(CanDoWin, maxdwell, resolution, &jrange, &jc, JULIA);
  150.       } /* else if */
  151.    } /* if argc >= 2 */
  152.  
  153.    CloseLibraries();
  154.  
  155. } /* main */
  156.